<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_agentmcp/model')->方法名();
*/
namespace jy_agentmcp;
defined('BY_JYA') or exit('error');
class member extends \plugin{
	public function upmember($mid=0){
		$mid=$mid?:$_SESSION['uid'];
		$member = pdo_get('jy_agentmcp_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid));
		if(empty($member)){
			$membernew=array(
				'uniacid' => $_SESSION['uniacid'],
				'mid' => $mid,
				'fromuser'=>$_SESSION['fromuser'],
				'createtime'=>time(),
			);
			pdo_insert('jy_agentmcp_member',$membernew);
			$basic=$this->plugin_setting('basic');
			if($basic['bi_new']>0){
				model('core/member')->member_credit($mid,'credit3',$basic['bi_new'],true,'jy_agentmcp','新用户赠送金币');
			}
			if($basic['bi_sale']>0 && $_SESSION['fromuser']){
				model('core/member')->member_credit($_SESSION['fromuser'],'credit3',$basic['bi_sale'],true,'jy_agentmcp','分享赚金币');
			}
			return $membernew;
		}
	}
	public function checkvip($mid=0,$isres=false){
		$mid=$mid?:$_SESSION['uid'];
		$basic=$this->plugin_setting('basic');
		if($basic['no_vip']){
			return '';
		}
		$member = pdo_get('jy_agentmcp_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid));
		if($member['viptime']<time()){
			$msg=$member['viptime']>0?'您的VIP已到期！请前往开通续费！':'请先开通VIP会员！';
			exi($msg,'error','jy_agentmcp/home/buyvip/');
		}
		return 'isvip';
	}
	//
	public function bi_up(){
		$basic=$this->plugin_setting('basic');
		$checkvip=$this->checkvip('',true);
		if($checkvip!='isvip'){
			if($basic['bi_open'] && $basic['bi_post']>0){
				$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
				if($basic['bi_post'] >0 && $basic['bi_post']>$member['credit3']){
					return 'fail';
					//return '您的金币不足，不能提问：1、分享好友赚金币；2、看广告赚金币；3、可开通VIP无限对话！';
				}
			}
		}
		return '';
	}
}
?>